
const path = require('path');
const fsExtra = require('fs-extra');
const fs = require('fs')
const outPath = path.resolve('./nect_echart_dist/')

async function removeDirExcept(dirPath, excludeDirs) {
    try {
        const files = fs.readdirSync(path.resolve(dirPath));
        for (const file of files) {
            if (excludeDirs.includes(file)) {
                continue
            } else {
                const filePath = path.resolve(dirPath, file);
                fsExtra.removeSync(filePath)
            }
        }

       
    } catch (err) {
        console.error(`Error removing directory: ${err}`);
    }
}
const copyDir = async () => {
    try {
        // await removeDirExcept('./nect_echart_dist', ['src'])
        await fsExtra.emptyDir(outPath);
        await fsExtra.remove(path.resolve('./.next/standalone/node_modules/'))
        await fsExtra.remove(path.resolve('./.next/standalone/prisma/'))
        // // 使用 fs-extra 的 copy 方法来复制目录
        await fsExtra.copy(path.resolve('./.next/standalone/'), outPath);
        await fsExtra.copy(path.resolve('./public'), path.resolve(outPath, 'public'));
        await fsExtra.copy(path.resolve('./send_email'), path.resolve(outPath, 'send_email'));
        await fsExtra.copy(path.resolve('./.next/static'), path.resolve(outPath, './.next/static'));
        await fsExtra.copyFile(path.resolve('./ecosystem.config.js'), path.resolve(outPath, './ecosystem.config.js'));
        await fsExtra.copyFile(path.resolve('./doctor_list.config.js'), path.resolve(outPath, './doctor_list.config.js'));
    } catch (error) {
        console.error('Error copying directory:', error);
    }
}

copyDir()